<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 冒泡排序
    /*
     mao(arr,str)
     return arr
     arr:一个数组
     str:从小到大："s-m"
         从大到小："m-s"
    */
    function mao(arr, str) {
        for (let i = 0; i < arr.length; i++) {
            for (let j = i + 1; j < arr.length; j++) {
                if (str === "s-m") {
                    if (arr[i] > arr[j]) {
                        // 数据交换
                        var number = arr[i]
                        arr[i] = arr[j]
                        arr[j] = number
                    } else {
                        continue;
                    }
                } else {
                    if (arr[i] < arr[j]) {
                        var number = arr[i]
                        arr[i] = arr[j]
                        arr[j] = number
                    } else {
                        continue;
                    }
                }
            }
        }
        return arr
    }
    console.log(mao([5, 6, 8, 9, 6, 2, 6, 1, 12, 123, 15, 14, 13], "m-s"))
</script>

</html>